#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<string,int>Ser;
int n;
bool Check(string s){
	register int ii=0;
	register ll x=0,flag=0,ok=1,h=0;
	while(ii<s.length()&&s[ii]>='0'&&s[ii]<='9'){
		x=(x<<1)+(x<<3)+s[ii]-'0',h=1;
		if(!flag&&s[ii]=='0') ok=0;
		flag|=(s[ii]!='0'),ii++;
	}
	if(!(x>=0&&x<=255)) return 0;
	if(s[ii]!='.') return 0;
	if(!ok&&x) return 0;
	if(!h) return 0;
	x=flag=h=0,ii++,ok=1;
	while(ii<s.length()&&s[ii]>='0'&&s[ii]<='9'){
		x=(x<<1)+(x<<3)+s[ii]-'0',h=1;
		if(!flag&&s[ii]=='0') ok=0;
		flag|=(s[ii]!='0'),ii++;
	}
	if(!(x>=0&&x<=255)) return 0;
	if(s[ii]!='.') return 0;
	if(!ok&&x) return 0;
	if(!h) return 0;
	x=flag=h=0,ii++,ok=1;
	while(ii<s.length()&&s[ii]>='0'&&s[ii]<='9'){
		x=(x<<1)+(x<<3)+s[ii]-'0',h=1;
		if(!flag&&s[ii]=='0') ok=0;
		flag|=(s[ii]!='0'),ii++;
	}
	if(!(x>=0&&x<=255)) return 0;
	if(s[ii]!='.') return 0;
	if(!ok&&x) return 0;
	if(!h) return 0;
	x=flag=h=0,ii++,ok=1;
	while(ii<s.length()&&s[ii]>='0'&&s[ii]<='9'){
		x=(x<<1)+(x<<3)+s[ii]-'0',h=1;
		if(!flag&&s[ii]=='0') ok=0;
		flag|=(s[ii]!='0'),ii++;
	}
	if(!(x>=0&&x<=255)) return 0;
	if(s[ii]!=':') return 0;
	if(!ok&&x) return 0;
	if(!h) return 0; 
	x=flag=h=0,ii++,ok=1;
	while(ii<s.length()&&s[ii]>='0'&&s[ii]<='9'){
		x=(x<<1)+(x<<3)+s[ii]-'0',h=1;
		if(!flag&&s[ii]=='0') ok=0;
		flag|=(s[ii]!='0'),ii++;
	}
	if(!(x>=0&&x<=65535)) return 0;
	if(ii!=s.length()) return 0;
	if(!ok&&x) return 0;
	if(!h) return 0;
	return 1;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	string a,b;
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		cin>>a>>b;
		if(!Check(b)){
			printf("ERR\n");
			continue;
		}
		if(a=="Server"){
			if(Ser[b]) printf("FAIL\n");
			else Ser[b]=i,printf("OK\n");
		}
		else{
			if(Ser[b]) printf("%d\n",Ser[b]);
			else printf("FAIL\n");
		}
	}
	return 0;
}//henghenghengaaaaaaaaaaaaaaa
